{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:55.437565Z",
     "start_time": "2018-10-16T07:02:55.026870Z"
    },
    "collapsed": true,
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "from torch.autograd import Variable\n",
    "from torch.optim.lr_scheduler import StepLR\n",
    "from torch.utils.data import DataLoader,TensorDataset\n",
    "import torch.utils.data as data\n",
    "import numpy as np\n",
    "import scipy.io as sio\n",
    "import math\n",
    "import argparse\n",
    "import random\n",
    "import os\n",
    "from My_Loss import HardTripletLoss\n",
    "from My_Loss import HardTripletLoss2\n",
    "from My_Loss import HardTripletLoss_D\n",
    "from tensorboardX import SummaryWriter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:55.441403Z",
     "start_time": "2018-10-16T07:02:55.438638Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "BATCH_SIZE = 64\n",
    "EPISODE = 100000\n",
    "TEST_EPISODE = 1000\n",
    "LEARNING_RATE =2e-5\n",
    "Weight_Deacy = 1e-6\n",
    "GPU = 0\n",
    "Margin = 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:56.161765Z",
     "start_time": "2018-10-16T07:02:55.442843Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init dataset\n",
      "----------------------------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "print(\"init dataset\")\n",
    "##################################参数##################################################################\n",
    "dataroot = '../data'\n",
    "dataset = 'CUB1_data'\n",
    "image_embedding = 'res101'               #ResNet101层\n",
    "class_embedding = 'original_att'         #属性表达 85-d\n",
    "#######################################读取视觉特征###################################################################\n",
    "\n",
    "matcontent = sio.loadmat(dataroot + \"/\" + dataset + \"/\" + image_embedding + \".mat\")  #scipy loadmat\n",
    " \n",
    "feature = matcontent['features'].T         #转置 30478x2048 每一行是一个完整的样本\n",
    "\n",
    "label = matcontent['labels'].astype(int).squeeze() - 1   #matlab begin 1 ,numpy begin 0\n",
    "########################################读取属性特征###########################################################\n",
    "\n",
    "matcontent = sio.loadmat(dataroot + \"/\" + dataset + \"/\" + class_embedding + \"_splits.mat\")\n",
    "\n",
    "    \n",
    "# numpy array index starts from 0, matlab starts from 1\n",
    "trainval_loc = matcontent['trainval_loc'].squeeze() - 1    #squeeze()去掉维度中的1 AxBx1 --->AxB\n",
    "\n",
    "test_seen_loc = matcontent['test_seen_loc'].squeeze() - 1\n",
    "test_unseen_loc = matcontent['test_unseen_loc'].squeeze() - 1\n",
    "\n",
    "attribute = matcontent['att'].T    #转置 50x85 每行是整个属性向量\n",
    "\n",
    "x = feature[trainval_loc]                      # train_features trainval里面是图片的编号 begin with 0 ，19832个\n",
    "train_label = label[trainval_loc].astype(int)  # train_label  int类型没变 每个图片的lable 19832个\n",
    "train_id = np.unique(train_label)\n",
    "\n",
    "att = attribute[train_label]                   # train attributes 每个图片的属性 19832个\n",
    "\n",
    "########################add negative pairs#######################\n",
    "#x_negative = np.empty_like(x)\n",
    "#x_negative_label = np.empty_like(train_label)\n",
    "#print(x.shape[0])\n",
    "\n",
    "#for i in range(x.shape[0]):\n",
    "#    pick=np.random.choice(np.where(train_label[i]!=train_id)[0], replace=True)\n",
    "#    x_negative[i] = x[pick]\n",
    "#    x_negative_label[i] = train_label[pick]\n",
    "    \n",
    "x_test = feature[test_unseen_loc]                   # test_feature 5685个\n",
    "test_label = label[test_unseen_loc].astype(int)     # test_label   5685个\n",
    "\n",
    "x_test_seen = feature[test_seen_loc]                #test_seen_feature 4958个\n",
    "test_label_seen = label[test_seen_loc].astype(int)  # test_seen_label  4958个\n",
    "    \n",
    "test_id = np.unique(test_label)                     # test_id  10个类 ，unique去重\n",
    "att_pro = attribute[test_id]                        # test_attribute 每一类的属性向量 10x85\n",
    "\n",
    "# train set\n",
    "train_features = torch.from_numpy(x)   #np-->tensor\n",
    "#train_fearures_negative = torch.from_numpy(x_negative)\n",
    "\n",
    "sample_attributes=[]\n",
    "train_label = torch.from_numpy(train_label).unsqueeze(1) #每张图片的属性转化 ，unsqueeze(1)就是插入到第一维度 AxB维-->Ax1xB\n",
    "#train_negative_label = torch.from_numpy(x_negative_label).unsqueeze(1)\n",
    "# attributes\n",
    "all_attributes = np.array(attribute)  #所有50类属性转变为numpy数组???属性向量仍然用的numpy类型 没有转化为pytorch\n",
    "#print(all_attributes)\n",
    "    \n",
    "#print('-'*50)\n",
    "attributes = torch.from_numpy(attribute) \n",
    "#print(attribute)\n",
    "# test set\n",
    "\n",
    "test_features = torch.from_numpy(x_test)\n",
    "#print(test_features.shape)\n",
    "\n",
    "test_label = torch.from_numpy(test_label).unsqueeze(1)\n",
    "#print(test_label.shape)\n",
    "\n",
    "testclasses_id = np.array(test_id)\n",
    "#print(testclasses_id.shape)\n",
    "\n",
    "test_attributes = torch.from_numpy(att_pro).float()\n",
    "#print(test_attributes.shape)\n",
    "\n",
    "test_seen_features = torch.from_numpy(x_test_seen)\n",
    "#print(test_seen_features.shape)\n",
    "\n",
    "test_seen_label = torch.from_numpy(test_label_seen)\n",
    "\n",
    "train_data = TensorDataset( train_label, train_features )\n",
    "#train_data = TensorDataset(train_label, train_features, train_fearures_negative)\n",
    "\n",
    "#################here need new code to make triplet data#####################\n",
    "print('-'*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:56.165017Z",
     "start_time": "2018-10-16T07:02:56.162750Z"
    },
    "collapsed": true,
    "hide_input": false
   },
   "outputs": [],
   "source": [
    "from my_net_3 import AttributeNetwork\n",
    "from my_net_3 import MetricNetwork"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:58.681643Z",
     "start_time": "2018-10-16T07:02:56.166346Z"
    },
    "hide_input": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init networks\n",
      "----------------------------------------------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "# init network\n",
    "print(\"init networks\")\n",
    "attribute_network = AttributeNetwork(312,1200,2048)  #85d属性 1024隐藏层 2048输出 85d到2048d\n",
    "metric_network = MetricNetwork(2048,1200,2048)\n",
    "#triplet_network = TripletNetwork(attribute_network, metric_network)  #metric learning   \n",
    "attribute_network.cuda(GPU) \n",
    "metric_network.cuda(GPU)\n",
    "#attribute_network_optim = torch.optim.Adam(attribute_network.parameters(), lr=LEARNING_RATE, weight_decay=1e-5)\n",
    "#优化器adam 学习率 正则1e-5\n",
    "\n",
    "#attribute_network_scheduler = StepLR(attribute_network_optim, step_size=200000, gamma=0.5)\n",
    "#学习率每200k步 乘0.5\n",
    "attribute_network_optim = torch.optim.Adam(attribute_network.parameters(), lr=LEARNING_RATE,weight_decay=Weight_Deacy)\n",
    "metric_network_optim = torch.optim.Adam(metric_network.parameters(), lr=LEARNING_RATE,weight_decay=Weight_Deacy)\n",
    "#\n",
    "#triplet_network_optim = torch.optim.SGD(triplet_network.parameters(), lr=LEARNING_RATE,momentum=0.9 , \n",
    "#                                         weight_decay=Weight_Deacy)\n",
    "\n",
    "attribute_network_scheduler = StepLR(attribute_network_optim , step_size=10000 , gamma=1)\n",
    "metric_network_scheduler = StepLR(metric_network_optim , step_size=10000 , gamma=1)\n",
    "#\n",
    "print('-'*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:58.687914Z",
     "start_time": "2018-10-16T07:02:58.682629Z"
    },
    "collapsed": true,
    "hide_input": true
   },
   "outputs": [],
   "source": [
    "def compute_accuracy(test_features, test_label, test_id, test_attributes):\n",
    "    \n",
    "    test_data = TensorDataset(test_features, test_label)\n",
    "    test_batch = 32\n",
    "    test_loader = DataLoader(test_data, batch_size=test_batch, shuffle=False)\n",
    "    total_rewards = 0\n",
    "\n",
    "    sample_labels = test_id\n",
    "    sample_attributes = test_attributes\n",
    "    class_num = sample_attributes.shape[0]\n",
    "    test_size = test_features.shape[0]\n",
    "\n",
    "    print(\"class num:\", class_num)\n",
    "\n",
    "    for batch_features,batch_labels in test_loader:\n",
    "\n",
    "        batch_size = batch_labels.shape[0]\n",
    "        batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(class_num, 0))\n",
    "        batch_features_ext = metric_network(Variable(batch_features_ext).cuda(GPU).float())  # 32*1024\n",
    "\n",
    "        #print(batch_features_ext)\n",
    "\n",
    "        sample_features = metric_network(attribute_network(Variable(sample_attributes).cuda(GPU).float()))\n",
    "        sample_features_ext = sample_features.repeat(batch_size, 1)\n",
    "        #print(sample_features_ext.shape)\n",
    "\n",
    "\n",
    "        relations = F.pairwise_distance(batch_features_ext, sample_features_ext, 2).view(-1, class_num)\n",
    "        re_batch_labels = []\n",
    "        for label in batch_labels.numpy():\n",
    "            index = np.argwhere(sample_labels == label)\n",
    "            re_batch_labels.append(index[0][0])\n",
    "        re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "\n",
    "\n",
    "        _, predict_labels = torch.min(relations.data, 1)\n",
    "        #print(predict_labels)\n",
    "        rewards = [1 if predict_labels[j] == re_batch_labels[j] else 0 for j in range(batch_size)]\n",
    "        total_rewards += np.sum(rewards)\n",
    "    test_accuracy = total_rewards/1.0/test_size\n",
    "    return  test_accuracy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T07:02:58.699244Z",
     "start_time": "2018-10-16T07:02:58.689963Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def compute_accuracy_per_class(test_features, test_label, test_id, test_attributes,cos_sim = False):\n",
    "    \n",
    "    test_data = TensorDataset(test_features, test_label)\n",
    "    test_batch = 32\n",
    "    test_loader = DataLoader(test_data, batch_size=test_batch, shuffle=False)\n",
    "    total_rewards = 0\n",
    "    #print(test_features.size())\n",
    "    sample_labels = test_id\n",
    "    sample_attributes = test_attributes\n",
    "    class_num = sample_attributes.shape[0]\n",
    "    test_size = test_features.shape[0]\n",
    "    per_class_num = np.zeros(class_num)\n",
    "    per_class_true= np.zeros(class_num)\n",
    "\n",
    "    print(\"class num:\", class_num)\n",
    "\n",
    "    for batch_features,batch_labels in test_loader:\n",
    "\n",
    "        batch_size = batch_labels.shape[0]\n",
    "        batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(class_num, 0))\n",
    "        batch_features_ext = metric_network(Variable(batch_features_ext).cuda(GPU).float())  # 32*1024\n",
    "\n",
    "\n",
    "        sample_features = metric_network(attribute_network(Variable(sample_attributes).cuda(GPU).float()))\n",
    "        sample_features_ext = sample_features.repeat(batch_size, 1)\n",
    "\n",
    "        if cos_sim:\n",
    "            relations = F.cosine_similarity(batch_features_ext, sample_features_ext).view(-1, class_num)\n",
    "        else:\n",
    "            relations = F.pairwise_distance(batch_features_ext, sample_features_ext, 2).view(-1, class_num)\n",
    "        re_batch_labels = []\n",
    "        for label in batch_labels.numpy():\n",
    "            index = np.argwhere(sample_labels == label)\n",
    "            re_batch_labels.append(index[0][0])\n",
    "        re_batch_labels_id, batch_per_num = np.unique(re_batch_labels , return_counts=True) \n",
    "        re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "        \n",
    "        for each in range(re_batch_labels_id.size):\n",
    "            #print(re_batch_labels_id[each])\n",
    "            #print(batch_per_num[each])\n",
    "            per_class_num[re_batch_labels_id[each]] = per_class_num[re_batch_labels_id[each]] + batch_per_num[each]\n",
    "        #print(re_batch_labels_id)\n",
    "        #print('-'*100)\n",
    "        #print(batch_per_num)\n",
    "        #print('-'*100)\n",
    "\n",
    "\n",
    "        _, predict_labels = torch.min(relations.data, 1)\n",
    "        for j in range(batch_size):\n",
    "            if predict_labels[j] == re_batch_labels[j]:\n",
    "                per_class_true[re_batch_labels[j]] = per_class_true[re_batch_labels[j]] + 1\n",
    "            \n",
    "        \n",
    "        \n",
    "    per_accuracy = per_class_true[np.nonzero(per_class_num)] / per_class_num[np.nonzero(per_class_num)]\n",
    "    \n",
    "\n",
    "    test_accuracy = np.sum(per_accuracy)/1.0/np.count_nonzero(per_class_num)\n",
    "    \n",
    "    #print(np.count_nonzero(per_class_num))\n",
    "    return  test_accuracy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-10-16T08:09:59.442869Z",
     "start_time": "2018-10-16T07:02:58.700519Z"
    },
    "code_folding": [],
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "training...\n",
      "episode: 1 loss tensor(3.0577, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.025333333333333333\n",
      "gzsl: unseen=0.0000 , seen=0.0067 , h=0.0000\n",
      "____________________________________________________________________________________________________\n",
      "episode: 200 loss tensor(2.9922, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.07602824858757062\n",
      "gzsl: unseen=0.0263 , seen=0.0568 , h=0.0360\n",
      "____________________________________________________________________________________________________\n",
      "episode: 400 loss tensor(2.9832, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.0754180790960452\n",
      "gzsl: unseen=0.0303 , seen=0.0442 , h=0.0360\n",
      "____________________________________________________________________________________________________\n",
      "episode: 600 loss tensor(2.9314, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.08617007597895966\n",
      "gzsl: unseen=0.0457 , seen=0.0599 , h=0.0519\n",
      "____________________________________________________________________________________________________\n",
      "episode: 800 loss tensor(2.8968, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.18319479579046422\n",
      "gzsl: unseen=0.1089 , seen=0.0923 , h=0.0999\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1000 loss tensor(2.9033, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.2527629030064437\n",
      "gzsl: unseen=0.1504 , seen=0.1410 , h=0.1455\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1200 loss tensor(2.7361, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.27978918871232755\n",
      "gzsl: unseen=0.1724 , seen=0.1654 , h=0.1688\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1400 loss tensor(2.8064, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.39875316284933965\n",
      "gzsl: unseen=0.2860 , seen=0.2138 , h=0.2447\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1600 loss tensor(2.6115, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.36870971626434934\n",
      "gzsl: unseen=0.2664 , seen=0.2174 , h=0.2394\n",
      "____________________________________________________________________________________________________\n",
      "episode: 1800 loss tensor(2.5900, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4238735404808902\n",
      "gzsl: unseen=0.3187 , seen=0.2617 , h=0.2874\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2000 loss tensor(2.5061, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.41411505479842653\n",
      "gzsl: unseen=0.2828 , seen=0.2980 , h=0.2902\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2200 loss tensor(2.3402, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.42854056055027895\n",
      "gzsl: unseen=0.3326 , seen=0.3018 , h=0.3165\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2400 loss tensor(2.1089, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4755096483144055\n",
      "gzsl: unseen=0.3731 , seen=0.3185 , h=0.3436\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2600 loss tensor(2.2120, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4683925465633029\n",
      "gzsl: unseen=0.3669 , seen=0.3283 , h=0.3465\n",
      "____________________________________________________________________________________________________\n",
      "episode: 2800 loss tensor(2.0640, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.46051382187977696\n",
      "gzsl: unseen=0.3532 , seen=0.3605 , h=0.3568\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3000 loss tensor(2.0793, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4544312070882188\n",
      "gzsl: unseen=0.3506 , seen=0.3508 , h=0.3507\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3200 loss tensor(2.0865, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.47121818937029725\n",
      "gzsl: unseen=0.3713 , seen=0.3931 , h=0.3819\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3400 loss tensor(1.8049, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.46503715202565915\n",
      "gzsl: unseen=0.3505 , seen=0.3852 , h=0.3671\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3600 loss tensor(2.0948, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.47910970586706275\n",
      "gzsl: unseen=0.3533 , seen=0.4079 , h=0.3786\n",
      "____________________________________________________________________________________________________\n",
      "episode: 3800 loss tensor(1.7761, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4683459966508135\n",
      "gzsl: unseen=0.3628 , seen=0.4036 , h=0.3821\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4000 loss tensor(2.0968, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.48172962727827917\n",
      "gzsl: unseen=0.3665 , seen=0.4187 , h=0.3909\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4200 loss tensor(2.1600, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4836275245583386\n",
      "gzsl: unseen=0.3730 , seen=0.4137 , h=0.3923\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4400 loss tensor(1.9666, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.48824708038415354\n",
      "gzsl: unseen=0.3737 , seen=0.4204 , h=0.3957\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4600 loss tensor(1.8548, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.49367145965826537\n",
      "gzsl: unseen=0.3738 , seen=0.4215 , h=0.3962\n",
      "____________________________________________________________________________________________________\n",
      "episode: 4800 loss tensor(1.8223, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4993463438571728\n",
      "gzsl: unseen=0.3866 , seen=0.4354 , h=0.4096\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5000 loss tensor(2.3662, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4685642478272033\n",
      "gzsl: unseen=0.3613 , seen=0.4214 , h=0.3890\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5200 loss tensor(1.5614, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5013726944673307\n",
      "gzsl: unseen=0.3940 , seen=0.4412 , h=0.4163\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5400 loss tensor(2.1830, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4990271784547218\n",
      "gzsl: unseen=0.3826 , seen=0.4509 , h=0.4140\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 5600 loss tensor(1.6927, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4932407087378692\n",
      "gzsl: unseen=0.3832 , seen=0.4470 , h=0.4126\n",
      "____________________________________________________________________________________________________\n",
      "episode: 5800 loss tensor(2.3258, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5130129400533413\n",
      "gzsl: unseen=0.3994 , seen=0.4378 , h=0.4177\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6000 loss tensor(2.0713, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4948200046945324\n",
      "gzsl: unseen=0.3880 , seen=0.4439 , h=0.4140\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6200 loss tensor(1.3361, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5141044275112204\n",
      "gzsl: unseen=0.3972 , seen=0.4550 , h=0.4242\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6400 loss tensor(1.8227, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5122402855998105\n",
      "gzsl: unseen=0.4000 , seen=0.4591 , h=0.4275\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6600 loss tensor(2.1859, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5060511296021778\n",
      "gzsl: unseen=0.3974 , seen=0.4705 , h=0.4309\n",
      "____________________________________________________________________________________________________\n",
      "episode: 6800 loss tensor(2.0171, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.4914678080051756\n",
      "gzsl: unseen=0.3705 , seen=0.4551 , h=0.4084\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7000 loss tensor(2.0276, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.49772893459844153\n",
      "gzsl: unseen=0.3982 , seen=0.4625 , h=0.4279\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7200 loss tensor(1.7315, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5104457510543006\n",
      "gzsl: unseen=0.3912 , seen=0.4753 , h=0.4291\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7400 loss tensor(1.4768, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5188518893917745\n",
      "gzsl: unseen=0.4059 , seen=0.4642 , h=0.4331\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7600 loss tensor(2.2376, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5156544768983319\n",
      "gzsl: unseen=0.3926 , seen=0.4662 , h=0.4262\n",
      "____________________________________________________________________________________________________\n",
      "episode: 7800 loss tensor(1.8750, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5134740239022068\n",
      "gzsl: unseen=0.4072 , seen=0.4690 , h=0.4359\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8000 loss tensor(1.7464, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5108508599553757\n",
      "gzsl: unseen=0.4035 , seen=0.4740 , h=0.4359\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8200 loss tensor(2.0085, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.510666769116698\n",
      "gzsl: unseen=0.3967 , seen=0.4749 , h=0.4323\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8400 loss tensor(2.0321, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5158515529502826\n",
      "gzsl: unseen=0.4038 , seen=0.4794 , h=0.4384\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8600 loss tensor(2.0261, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5308977907866388\n",
      "gzsl: unseen=0.4150 , seen=0.4630 , h=0.4377\n",
      "____________________________________________________________________________________________________\n",
      "episode: 8800 loss tensor(1.3839, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.520903003450534\n",
      "gzsl: unseen=0.4035 , seen=0.4777 , h=0.4375\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9000 loss tensor(1.5269, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5213809743307798\n",
      "gzsl: unseen=0.4055 , seen=0.4716 , h=0.4361\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9200 loss tensor(1.8069, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5277488654617367\n",
      "gzsl: unseen=0.4104 , seen=0.4838 , h=0.4441\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9400 loss tensor(1.6093, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.526380765597374\n",
      "gzsl: unseen=0.4041 , seen=0.4776 , h=0.4378\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9600 loss tensor(1.5115, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5452972972831049\n",
      "gzsl: unseen=0.4305 , seen=0.4768 , h=0.4524\n",
      "____________________________________________________________________________________________________\n",
      "episode: 9800 loss tensor(1.7160, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5380665651618433\n",
      "gzsl: unseen=0.4274 , seen=0.4726 , h=0.4489\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10000 loss tensor(1.7462, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5281198005296316\n",
      "gzsl: unseen=0.4125 , seen=0.4959 , h=0.4503\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10200 loss tensor(2.3004, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.520031817114879\n",
      "gzsl: unseen=0.4048 , seen=0.4804 , h=0.4394\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10400 loss tensor(1.8201, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5244425515781558\n",
      "gzsl: unseen=0.4123 , seen=0.4787 , h=0.4430\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10600 loss tensor(1.7378, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5369446120788114\n",
      "gzsl: unseen=0.4233 , seen=0.4791 , h=0.4495\n",
      "____________________________________________________________________________________________________\n",
      "episode: 10800 loss tensor(1.5399, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.514734153038607\n",
      "gzsl: unseen=0.4029 , seen=0.5079 , h=0.4493\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11000 loss tensor(1.6092, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5287371532334249\n",
      "gzsl: unseen=0.4099 , seen=0.4995 , h=0.4503\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 11200 loss tensor(1.6744, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5408099493106022\n",
      "gzsl: unseen=0.4227 , seen=0.4969 , h=0.4568\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11400 loss tensor(1.5177, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.524135534459916\n",
      "gzsl: unseen=0.4120 , seen=0.4842 , h=0.4452\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11600 loss tensor(1.5433, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5362410607227794\n",
      "gzsl: unseen=0.4279 , seen=0.4843 , h=0.4544\n",
      "____________________________________________________________________________________________________\n",
      "episode: 11800 loss tensor(2.1506, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5237059275036063\n",
      "gzsl: unseen=0.4188 , seen=0.4804 , h=0.4475\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12000 loss tensor(1.5696, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.533175519431111\n",
      "gzsl: unseen=0.4223 , seen=0.4884 , h=0.4529\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12200 loss tensor(1.5250, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5217785437812411\n",
      "gzsl: unseen=0.4042 , seen=0.4883 , h=0.4423\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12400 loss tensor(1.5986, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5354874598746129\n",
      "gzsl: unseen=0.4240 , seen=0.4863 , h=0.4530\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12600 loss tensor(1.7145, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5270269699313621\n",
      "gzsl: unseen=0.4147 , seen=0.4984 , h=0.4527\n",
      "____________________________________________________________________________________________________\n",
      "episode: 12800 loss tensor(1.7611, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5447121664532072\n",
      "gzsl: unseen=0.4267 , seen=0.4961 , h=0.4588\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13000 loss tensor(1.5779, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5411639732968273\n",
      "gzsl: unseen=0.4282 , seen=0.4856 , h=0.4551\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13200 loss tensor(1.7585, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5394358145565163\n",
      "gzsl: unseen=0.4252 , seen=0.4967 , h=0.4582\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13400 loss tensor(1.8084, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.542772604620071\n",
      "gzsl: unseen=0.4208 , seen=0.4991 , h=0.4566\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13600 loss tensor(1.4035, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5329966321193189\n",
      "gzsl: unseen=0.4118 , seen=0.4932 , h=0.4489\n",
      "____________________________________________________________________________________________________\n",
      "episode: 13800 loss tensor(1.8160, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5286760981083765\n",
      "gzsl: unseen=0.4224 , seen=0.4986 , h=0.4573\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14000 loss tensor(1.8243, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5315691478898497\n",
      "gzsl: unseen=0.4151 , seen=0.4965 , h=0.4522\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14200 loss tensor(1.1584, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5449325480756356\n",
      "gzsl: unseen=0.4272 , seen=0.5005 , h=0.4610\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14400 loss tensor(1.4358, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5336456381544711\n",
      "gzsl: unseen=0.4290 , seen=0.4926 , h=0.4586\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14600 loss tensor(1.7202, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5406557592303487\n",
      "gzsl: unseen=0.4335 , seen=0.4882 , h=0.4592\n",
      "____________________________________________________________________________________________________\n",
      "episode: 14800 loss tensor(1.9006, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5365688249438257\n",
      "gzsl: unseen=0.4188 , seen=0.4984 , h=0.4551\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15000 loss tensor(1.9364, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5397828733059118\n",
      "gzsl: unseen=0.4247 , seen=0.4982 , h=0.4585\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15200 loss tensor(1.8134, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5331081355092019\n",
      "gzsl: unseen=0.4251 , seen=0.5024 , h=0.4605\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15400 loss tensor(1.9673, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5303057048546402\n",
      "gzsl: unseen=0.4286 , seen=0.5017 , h=0.4622\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15600 loss tensor(1.5761, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5347181056143773\n",
      "gzsl: unseen=0.4233 , seen=0.4900 , h=0.4542\n",
      "____________________________________________________________________________________________________\n",
      "episode: 15800 loss tensor(1.4329, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5309035016275954\n",
      "gzsl: unseen=0.4205 , seen=0.4984 , h=0.4561\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16000 loss tensor(1.3703, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5296751250168693\n",
      "gzsl: unseen=0.4224 , seen=0.4988 , h=0.4574\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16200 loss tensor(1.3808, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5394077607867911\n",
      "gzsl: unseen=0.4272 , seen=0.4966 , h=0.4593\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16400 loss tensor(1.5054, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.537349127179295\n",
      "gzsl: unseen=0.4304 , seen=0.4980 , h=0.4617\n",
      "____________________________________________________________________________________________________\n",
      "episode: 16600 loss tensor(1.7482, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5484506270666576\n",
      "gzsl: unseen=0.4415 , seen=0.5008 , h=0.4693\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 16800 loss tensor(1.3099, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5417485909313605\n",
      "gzsl: unseen=0.4336 , seen=0.5017 , h=0.4652\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17000 loss tensor(1.2797, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5431345566948811\n",
      "gzsl: unseen=0.4387 , seen=0.5011 , h=0.4679\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17200 loss tensor(1.3567, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5378496539751505\n",
      "gzsl: unseen=0.4310 , seen=0.4993 , h=0.4626\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17400 loss tensor(1.4621, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5360186521020636\n",
      "gzsl: unseen=0.4315 , seen=0.4940 , h=0.4606\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17600 loss tensor(1.6797, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5322297947901192\n",
      "gzsl: unseen=0.4237 , seen=0.4974 , h=0.4576\n",
      "____________________________________________________________________________________________________\n",
      "episode: 17800 loss tensor(1.4327, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5444590880424378\n",
      "gzsl: unseen=0.4430 , seen=0.4946 , h=0.4674\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18000 loss tensor(1.7565, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5432579199230392\n",
      "gzsl: unseen=0.4376 , seen=0.4994 , h=0.4664\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18200 loss tensor(1.4455, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5394832629416024\n",
      "gzsl: unseen=0.4286 , seen=0.5003 , h=0.4616\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18400 loss tensor(1.2040, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5350191457106203\n",
      "gzsl: unseen=0.4159 , seen=0.5042 , h=0.4558\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18600 loss tensor(1.9491, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5375381126194179\n",
      "gzsl: unseen=0.4213 , seen=0.5044 , h=0.4591\n",
      "____________________________________________________________________________________________________\n",
      "episode: 18800 loss tensor(1.5828, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5391951746612874\n",
      "gzsl: unseen=0.4383 , seen=0.4996 , h=0.4669\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19000 loss tensor(1.8970, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5286857742013913\n",
      "gzsl: unseen=0.4236 , seen=0.5038 , h=0.4602\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19200 loss tensor(1.2357, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5276465109489203\n",
      "gzsl: unseen=0.4266 , seen=0.5053 , h=0.4626\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19400 loss tensor(1.6783, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5268380606329847\n",
      "gzsl: unseen=0.4269 , seen=0.5079 , h=0.4639\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19600 loss tensor(1.4850, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5341709662597547\n",
      "gzsl: unseen=0.4351 , seen=0.5071 , h=0.4684\n",
      "____________________________________________________________________________________________________\n",
      "episode: 19800 loss tensor(1.5490, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5379212014327251\n",
      "gzsl: unseen=0.4363 , seen=0.5021 , h=0.4669\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20000 loss tensor(0.7872, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5319373814486151\n",
      "gzsl: unseen=0.4352 , seen=0.4973 , h=0.4642\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20200 loss tensor(1.3200, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5341276200768454\n",
      "gzsl: unseen=0.4360 , seen=0.4964 , h=0.4642\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20400 loss tensor(1.4743, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5200124847257033\n",
      "gzsl: unseen=0.4208 , seen=0.5017 , h=0.4577\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20600 loss tensor(0.9880, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5334952126271371\n",
      "gzsl: unseen=0.4233 , seen=0.4983 , h=0.4577\n",
      "____________________________________________________________________________________________________\n",
      "episode: 20800 loss tensor(1.4647, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5252908117392718\n",
      "gzsl: unseen=0.4228 , seen=0.5045 , h=0.4601\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21000 loss tensor(1.4554, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5535300138683\n",
      "gzsl: unseen=0.4503 , seen=0.5026 , h=0.4750\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21200 loss tensor(1.1159, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5249850098432897\n",
      "gzsl: unseen=0.4181 , seen=0.5185 , h=0.4629\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21400 loss tensor(1.2062, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5343358953717897\n",
      "gzsl: unseen=0.4275 , seen=0.5047 , h=0.4629\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21600 loss tensor(1.5924, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5522137425873385\n",
      "gzsl: unseen=0.4377 , seen=0.5106 , h=0.4714\n",
      "____________________________________________________________________________________________________\n",
      "episode: 21800 loss tensor(1.2881, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5387303597618707\n",
      "gzsl: unseen=0.4429 , seen=0.4977 , h=0.4687\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22000 loss tensor(1.4645, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5317968316106919\n",
      "gzsl: unseen=0.4342 , seen=0.5001 , h=0.4648\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22200 loss tensor(1.1776, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.516719643782659\n",
      "gzsl: unseen=0.4072 , seen=0.5126 , h=0.4539\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 22400 loss tensor(1.2718, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.528021324992399\n",
      "gzsl: unseen=0.4216 , seen=0.5011 , h=0.4579\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22600 loss tensor(1.7689, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5285818956459\n",
      "gzsl: unseen=0.4300 , seen=0.4994 , h=0.4621\n",
      "____________________________________________________________________________________________________\n",
      "episode: 22800 loss tensor(1.1837, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5335334693907557\n",
      "gzsl: unseen=0.4293 , seen=0.5118 , h=0.4669\n",
      "____________________________________________________________________________________________________\n",
      "episode: 23000 loss tensor(1.7962, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5395376283579165\n",
      "gzsl: unseen=0.4361 , seen=0.5038 , h=0.4675\n",
      "____________________________________________________________________________________________________\n",
      "episode: 23200 loss tensor(1.4033, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5356908544836723\n",
      "gzsl: unseen=0.4326 , seen=0.5020 , h=0.4647\n",
      "____________________________________________________________________________________________________\n",
      "episode: 23400 loss tensor(1.3018, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5264316557994018\n",
      "gzsl: unseen=0.4276 , seen=0.4994 , h=0.4607\n",
      "____________________________________________________________________________________________________\n",
      "episode: 23600 loss tensor(1.7502, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5336973111986655\n",
      "gzsl: unseen=0.4336 , seen=0.5044 , h=0.4663\n",
      "____________________________________________________________________________________________________\n",
      "episode: 23800 loss tensor(1.0872, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5212395746459539\n",
      "gzsl: unseen=0.4275 , seen=0.5024 , h=0.4619\n",
      "____________________________________________________________________________________________________\n",
      "episode: 24000 loss tensor(1.0742, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5252052682211136\n",
      "gzsl: unseen=0.4259 , seen=0.4972 , h=0.4588\n",
      "____________________________________________________________________________________________________\n",
      "episode: 24200 loss tensor(1.8279, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.520169143426368\n",
      "gzsl: unseen=0.4248 , seen=0.4968 , h=0.4580\n",
      "____________________________________________________________________________________________________\n",
      "episode: 24400 loss tensor(1.6896, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5174371060255426\n",
      "gzsl: unseen=0.4190 , seen=0.4933 , h=0.4531\n",
      "____________________________________________________________________________________________________\n",
      "episode: 24600 loss tensor(1.3658, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5163528825952046\n",
      "gzsl: unseen=0.4222 , seen=0.4993 , h=0.4576\n",
      "____________________________________________________________________________________________________\n",
      "episode: 24800 loss tensor(1.0615, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5226665271959936\n",
      "gzsl: unseen=0.4171 , seen=0.5029 , h=0.4560\n",
      "____________________________________________________________________________________________________\n",
      "episode: 25000 loss tensor(0.9481, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5369631280184294\n",
      "gzsl: unseen=0.4271 , seen=0.5119 , h=0.4657\n",
      "____________________________________________________________________________________________________\n",
      "episode: 25200 loss tensor(1.3825, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5306864915616567\n",
      "gzsl: unseen=0.4266 , seen=0.5058 , h=0.4629\n",
      "____________________________________________________________________________________________________\n",
      "episode: 25400 loss tensor(1.4717, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5214862585679155\n",
      "gzsl: unseen=0.4277 , seen=0.4979 , h=0.4602\n",
      "____________________________________________________________________________________________________\n",
      "episode: 25600 loss tensor(1.2878, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5258758089797899\n",
      "gzsl: unseen=0.4284 , seen=0.4982 , h=0.4607\n",
      "____________________________________________________________________________________________________\n",
      "episode: 25800 loss tensor(1.0456, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5379502616913024\n",
      "gzsl: unseen=0.4388 , seen=0.5028 , h=0.4686\n",
      "____________________________________________________________________________________________________\n",
      "episode: 26000 loss tensor(1.5479, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.534701185290675\n",
      "gzsl: unseen=0.4440 , seen=0.4903 , h=0.4660\n",
      "____________________________________________________________________________________________________\n",
      "episode: 26200 loss tensor(0.9731, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5233814160579265\n",
      "gzsl: unseen=0.4277 , seen=0.4872 , h=0.4555\n",
      "____________________________________________________________________________________________________\n",
      "episode: 26400 loss tensor(1.0385, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5236640828359177\n",
      "gzsl: unseen=0.4221 , seen=0.5027 , h=0.4589\n",
      "____________________________________________________________________________________________________\n",
      "episode: 26600 loss tensor(1.2331, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5209843216269339\n",
      "gzsl: unseen=0.4308 , seen=0.4916 , h=0.4592\n",
      "____________________________________________________________________________________________________\n",
      "episode: 26800 loss tensor(0.7078, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5165906642343318\n",
      "gzsl: unseen=0.4248 , seen=0.4980 , h=0.4585\n",
      "____________________________________________________________________________________________________\n",
      "episode: 27000 loss tensor(1.3358, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5247910065571171\n",
      "gzsl: unseen=0.4229 , seen=0.5049 , h=0.4603\n",
      "____________________________________________________________________________________________________\n",
      "episode: 27200 loss tensor(1.0526, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5206167671475149\n",
      "gzsl: unseen=0.4177 , seen=0.4900 , h=0.4510\n",
      "____________________________________________________________________________________________________\n",
      "episode: 27400 loss tensor(1.1866, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5144926301091767\n",
      "gzsl: unseen=0.4269 , seen=0.4985 , h=0.4599\n",
      "____________________________________________________________________________________________________\n",
      "episode: 27600 loss tensor(1.3400, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5179096888008095\n",
      "gzsl: unseen=0.4201 , seen=0.5048 , h=0.4586\n",
      "____________________________________________________________________________________________________\n",
      "episode: 27800 loss tensor(1.3882, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5198480400852157\n",
      "gzsl: unseen=0.4166 , seen=0.5068 , h=0.4573\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 28000 loss tensor(1.5132, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5188911393588235\n",
      "gzsl: unseen=0.4215 , seen=0.4953 , h=0.4554\n",
      "____________________________________________________________________________________________________\n",
      "episode: 28200 loss tensor(1.3983, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5064460935871322\n",
      "gzsl: unseen=0.4079 , seen=0.5049 , h=0.4512\n",
      "____________________________________________________________________________________________________\n",
      "episode: 28400 loss tensor(0.9655, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5239944483740586\n",
      "gzsl: unseen=0.4302 , seen=0.5046 , h=0.4644\n",
      "____________________________________________________________________________________________________\n",
      "episode: 28600 loss tensor(1.0509, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.524254843796522\n",
      "gzsl: unseen=0.4303 , seen=0.4962 , h=0.4609\n",
      "____________________________________________________________________________________________________\n",
      "episode: 28800 loss tensor(0.8454, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5224596242903721\n",
      "gzsl: unseen=0.4267 , seen=0.5030 , h=0.4617\n",
      "____________________________________________________________________________________________________\n",
      "episode: 29000 loss tensor(1.2062, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5187480446537205\n",
      "gzsl: unseen=0.4224 , seen=0.4986 , h=0.4573\n",
      "____________________________________________________________________________________________________\n",
      "episode: 29200 loss tensor(1.1540, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5404031605125758\n",
      "gzsl: unseen=0.4444 , seen=0.4989 , h=0.4700\n",
      "____________________________________________________________________________________________________\n",
      "episode: 29400 loss tensor(1.2269, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5176883143950434\n",
      "gzsl: unseen=0.4236 , seen=0.4936 , h=0.4559\n",
      "____________________________________________________________________________________________________\n",
      "episode: 29600 loss tensor(0.9505, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5168081692216161\n",
      "gzsl: unseen=0.4176 , seen=0.4908 , h=0.4513\n",
      "____________________________________________________________________________________________________\n",
      "episode: 29800 loss tensor(1.4302, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.521384316953406\n",
      "gzsl: unseen=0.4223 , seen=0.5032 , h=0.4592\n",
      "____________________________________________________________________________________________________\n",
      "episode: 30000 loss tensor(0.8522, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5224770956702653\n",
      "gzsl: unseen=0.4245 , seen=0.5022 , h=0.4601\n",
      "____________________________________________________________________________________________________\n",
      "episode: 30200 loss tensor(1.1538, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5262331131524101\n",
      "gzsl: unseen=0.4306 , seen=0.4892 , h=0.4580\n",
      "____________________________________________________________________________________________________\n",
      "episode: 30400 loss tensor(0.8836, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.519239408656949\n",
      "gzsl: unseen=0.4266 , seen=0.4892 , h=0.4558\n",
      "____________________________________________________________________________________________________\n",
      "episode: 30600 loss tensor(1.0535, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5204189126118561\n",
      "gzsl: unseen=0.4148 , seen=0.4986 , h=0.4528\n",
      "____________________________________________________________________________________________________\n",
      "episode: 30800 loss tensor(1.2445, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5311257686246648\n",
      "gzsl: unseen=0.4293 , seen=0.4972 , h=0.4608\n",
      "____________________________________________________________________________________________________\n",
      "episode: 31000 loss tensor(1.1850, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5043966550668655\n",
      "gzsl: unseen=0.4064 , seen=0.4939 , h=0.4459\n",
      "____________________________________________________________________________________________________\n",
      "episode: 31200 loss tensor(0.7805, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5288310481882729\n",
      "gzsl: unseen=0.4352 , seen=0.4868 , h=0.4596\n",
      "____________________________________________________________________________________________________\n",
      "episode: 31400 loss tensor(1.2039, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5286001926123602\n",
      "gzsl: unseen=0.4301 , seen=0.4928 , h=0.4593\n",
      "____________________________________________________________________________________________________\n",
      "episode: 31600 loss tensor(1.1167, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5199559449111846\n",
      "gzsl: unseen=0.4229 , seen=0.4976 , h=0.4572\n",
      "____________________________________________________________________________________________________\n",
      "episode: 31800 loss tensor(0.9753, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5116610390040028\n",
      "gzsl: unseen=0.4060 , seen=0.4978 , h=0.4472\n",
      "____________________________________________________________________________________________________\n",
      "episode: 32000 loss tensor(0.7312, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5219327142746869\n",
      "gzsl: unseen=0.4094 , seen=0.5034 , h=0.4516\n",
      "____________________________________________________________________________________________________\n",
      "episode: 32200 loss tensor(1.0005, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5210872835408328\n",
      "gzsl: unseen=0.4156 , seen=0.4997 , h=0.4538\n",
      "____________________________________________________________________________________________________\n",
      "episode: 32400 loss tensor(1.0523, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5171082878977158\n",
      "gzsl: unseen=0.4236 , seen=0.4923 , h=0.4554\n",
      "____________________________________________________________________________________________________\n",
      "episode: 32600 loss tensor(0.6725, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5161153996417663\n",
      "gzsl: unseen=0.4140 , seen=0.4906 , h=0.4491\n",
      "____________________________________________________________________________________________________\n",
      "episode: 32800 loss tensor(0.9476, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5105711323537829\n",
      "gzsl: unseen=0.4177 , seen=0.4911 , h=0.4515\n",
      "____________________________________________________________________________________________________\n",
      "episode: 33000 loss tensor(1.2482, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.511504617865584\n",
      "gzsl: unseen=0.4209 , seen=0.4913 , h=0.4534\n",
      "____________________________________________________________________________________________________\n",
      "episode: 33200 loss tensor(0.9082, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.512698412418351\n",
      "gzsl: unseen=0.4173 , seen=0.4899 , h=0.4507\n",
      "____________________________________________________________________________________________________\n",
      "episode: 33400 loss tensor(1.0590, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5210257499305535\n",
      "gzsl: unseen=0.4229 , seen=0.4901 , h=0.4540\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 33600 loss tensor(0.9448, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5101458605933911\n",
      "gzsl: unseen=0.4244 , seen=0.4841 , h=0.4523\n",
      "____________________________________________________________________________________________________\n",
      "episode: 33800 loss tensor(0.7443, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5112989876298545\n",
      "gzsl: unseen=0.4193 , seen=0.4968 , h=0.4547\n",
      "____________________________________________________________________________________________________\n",
      "episode: 34000 loss tensor(0.7333, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5161619981799497\n",
      "gzsl: unseen=0.4208 , seen=0.4890 , h=0.4523\n",
      "____________________________________________________________________________________________________\n",
      "episode: 34200 loss tensor(0.5779, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5223314608765333\n",
      "gzsl: unseen=0.4112 , seen=0.4949 , h=0.4492\n",
      "____________________________________________________________________________________________________\n",
      "episode: 34400 loss tensor(0.9316, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.533324463135055\n",
      "gzsl: unseen=0.4361 , seen=0.4943 , h=0.4634\n",
      "____________________________________________________________________________________________________\n",
      "episode: 34600 loss tensor(0.8616, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5128103389462928\n",
      "gzsl: unseen=0.4180 , seen=0.4939 , h=0.4528\n",
      "____________________________________________________________________________________________________\n",
      "episode: 34800 loss tensor(1.7666, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5214525411651159\n",
      "gzsl: unseen=0.4276 , seen=0.4816 , h=0.4530\n",
      "____________________________________________________________________________________________________\n",
      "episode: 35000 loss tensor(0.4520, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5227410895516196\n",
      "gzsl: unseen=0.4206 , seen=0.4981 , h=0.4560\n",
      "____________________________________________________________________________________________________\n",
      "episode: 35200 loss tensor(1.6104, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5083646189788289\n",
      "gzsl: unseen=0.4140 , seen=0.4983 , h=0.4523\n",
      "____________________________________________________________________________________________________\n",
      "episode: 35400 loss tensor(0.8042, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5079501003758251\n",
      "gzsl: unseen=0.4094 , seen=0.4970 , h=0.4490\n",
      "____________________________________________________________________________________________________\n",
      "episode: 35600 loss tensor(0.5575, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5151194350492532\n",
      "gzsl: unseen=0.4220 , seen=0.4814 , h=0.4498\n",
      "____________________________________________________________________________________________________\n",
      "episode: 35800 loss tensor(0.6665, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5138638833445445\n",
      "gzsl: unseen=0.4144 , seen=0.4914 , h=0.4496\n",
      "____________________________________________________________________________________________________\n",
      "episode: 36000 loss tensor(1.0945, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5122373482613163\n",
      "gzsl: unseen=0.4134 , seen=0.5002 , h=0.4527\n",
      "____________________________________________________________________________________________________\n",
      "episode: 36200 loss tensor(0.6912, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5137496875825416\n",
      "gzsl: unseen=0.4211 , seen=0.4935 , h=0.4545\n",
      "____________________________________________________________________________________________________\n",
      "episode: 36400 loss tensor(0.9561, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5069846824337843\n",
      "gzsl: unseen=0.4200 , seen=0.4770 , h=0.4467\n",
      "____________________________________________________________________________________________________\n",
      "episode: 36600 loss tensor(0.7273, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5088359425796718\n",
      "gzsl: unseen=0.4144 , seen=0.4885 , h=0.4484\n",
      "____________________________________________________________________________________________________\n",
      "episode: 36800 loss tensor(1.0137, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5086276674947738\n",
      "gzsl: unseen=0.4097 , seen=0.4912 , h=0.4467\n",
      "____________________________________________________________________________________________________\n",
      "episode: 37000 loss tensor(0.9892, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5132447492389764\n",
      "gzsl: unseen=0.4167 , seen=0.4922 , h=0.4513\n",
      "____________________________________________________________________________________________________\n",
      "episode: 37200 loss tensor(0.8655, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5144185760653411\n",
      "gzsl: unseen=0.4114 , seen=0.4946 , h=0.4492\n",
      "____________________________________________________________________________________________________\n",
      "episode: 37400 loss tensor(0.7477, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5169713698110057\n",
      "gzsl: unseen=0.4204 , seen=0.4873 , h=0.4514\n",
      "____________________________________________________________________________________________________\n",
      "episode: 37600 loss tensor(1.2671, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.514154795380874\n",
      "gzsl: unseen=0.4244 , seen=0.4833 , h=0.4519\n",
      "____________________________________________________________________________________________________\n",
      "episode: 37800 loss tensor(0.7879, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5203010332172302\n",
      "gzsl: unseen=0.4299 , seen=0.4855 , h=0.4560\n",
      "____________________________________________________________________________________________________\n",
      "episode: 38000 loss tensor(0.8562, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5078170044997147\n",
      "gzsl: unseen=0.4157 , seen=0.4964 , h=0.4525\n",
      "____________________________________________________________________________________________________\n",
      "episode: 38200 loss tensor(0.7541, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5334900381391379\n",
      "gzsl: unseen=0.4307 , seen=0.4904 , h=0.4586\n",
      "____________________________________________________________________________________________________\n",
      "episode: 38400 loss tensor(0.4327, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.514070876412495\n",
      "gzsl: unseen=0.4201 , seen=0.4896 , h=0.4522\n",
      "____________________________________________________________________________________________________\n",
      "episode: 38600 loss tensor(0.6255, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5076602272279731\n",
      "gzsl: unseen=0.4128 , seen=0.4843 , h=0.4457\n",
      "____________________________________________________________________________________________________\n",
      "episode: 38800 loss tensor(1.0403, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5163012464141176\n",
      "gzsl: unseen=0.4283 , seen=0.4858 , h=0.4552\n",
      "____________________________________________________________________________________________________\n",
      "episode: 39000 loss tensor(0.8204, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5043988067275695\n",
      "gzsl: unseen=0.4155 , seen=0.4841 , h=0.4472\n",
      "____________________________________________________________________________________________________\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "episode: 39200 loss tensor(0.3173, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5034528535563184\n",
      "gzsl: unseen=0.4157 , seen=0.4959 , h=0.4523\n",
      "____________________________________________________________________________________________________\n",
      "episode: 39400 loss tensor(0.7476, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5044127360984865\n",
      "gzsl: unseen=0.4105 , seen=0.4965 , h=0.4494\n",
      "____________________________________________________________________________________________________\n",
      "episode: 39600 loss tensor(0.4783, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5085743560902631\n",
      "gzsl: unseen=0.4203 , seen=0.4891 , h=0.4521\n",
      "____________________________________________________________________________________________________\n",
      "episode: 39800 loss tensor(0.6974, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5165337541608839\n",
      "gzsl: unseen=0.4172 , seen=0.4861 , h=0.4491\n",
      "____________________________________________________________________________________________________\n",
      "episode: 40000 loss tensor(0.7847, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.49649526918207487\n",
      "gzsl: unseen=0.4026 , seen=0.4978 , h=0.4452\n",
      "____________________________________________________________________________________________________\n",
      "episode: 40200 loss tensor(0.8843, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5117501475837074\n",
      "gzsl: unseen=0.4143 , seen=0.4882 , h=0.4482\n",
      "____________________________________________________________________________________________________\n",
      "episode: 40400 loss tensor(0.5335, device='cuda:0')\n",
      "loss_zero_number=  0\n",
      "Testing...\n",
      "class num: 50\n",
      "class num: 200\n",
      "class num: 200\n",
      "zsl: 0.5137041333940366\n",
      "gzsl: unseen=0.4096 , seen=0.4928 , h=0.4473\n",
      "____________________________________________________________________________________________________\n",
      "episode: 40600 loss tensor(0.6736, device='cuda:0')\n",
      "loss_zero_number=  1\n",
      "Testing...\n",
      "class num: 50\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-62f4d61da83e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     51\u001b[0m         \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Testing...\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     52\u001b[0m         \u001b[0;31m#attribute_network.eval()\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 53\u001b[0;31m         \u001b[0mzsl_accuracy\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompute_accuracy_per_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtest_features\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_label\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_id\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_attributes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     54\u001b[0m         \u001b[0mgzsl_unseen_accuracy\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcompute_accuracy_per_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtest_features\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_label\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m200\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mattributes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     55\u001b[0m         \u001b[0mgzsl_seen_accuracy\u001b[0m  \u001b[0;34m=\u001b[0m \u001b[0mcompute_accuracy_per_class\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtest_seen_features\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtest_seen_label\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m200\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mattributes\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-7-04dfd583a8d9>\u001b[0m in \u001b[0;36mcompute_accuracy_per_class\u001b[0;34m(test_features, test_label, test_id, test_attributes, cos_sim)\u001b[0m\n\u001b[1;32m     19\u001b[0m         \u001b[0mbatch_size\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbatch_labels\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     20\u001b[0m         \u001b[0mbatch_features_ext\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfrom_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch_features\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mclass_num\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 21\u001b[0;31m         \u001b[0mbatch_features_ext\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmetric_network\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mVariable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch_features_ext\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcuda\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mGPU\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m  \u001b[0;31m# 32*1024\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "print(\"training...\")\n",
    "last_accuracy = 0.0\n",
    "loss_zero_num = 0\n",
    "#writer = SummaryWriter()\n",
    "for episode in range(EPISODE):\n",
    "    #attribute_network.train()\n",
    "    attribute_network_scheduler.step(episode)\n",
    "    metric_network_scheduler.step(episode)\n",
    "\n",
    "    train_loader = DataLoader(train_data, batch_size=BATCH_SIZE, shuffle=True)\n",
    "\n",
    "    batch_labels, batch_features = train_loader.__iter__().next()\n",
    "    batch_id = np.unique(batch_labels)\n",
    "\n",
    "    batch_attributes = torch.Tensor([all_attributes[i] for i in batch_id]).squeeze(1)\n",
    "    batch_features_ext = torch.from_numpy(batch_features.numpy().repeat(batch_id.size, 0))\n",
    "    batch_attributes_ext = batch_attributes.repeat(BATCH_SIZE, 1)\n",
    "\n",
    "    batch_features_ext = Variable(batch_features_ext).cuda(GPU).float()  # 32*2048\n",
    "    batch_attributes_ext = Variable(batch_attributes_ext).cuda(GPU)\n",
    "    \n",
    "\n",
    "    re_batch_labels = []\n",
    "    for label in batch_labels.numpy():\n",
    "        index = np.argwhere(batch_id == label)\n",
    "        re_batch_labels.append(index[0][0])\n",
    "    re_batch_labels = torch.cuda.LongTensor(re_batch_labels)\n",
    "    re_batch_labels = Variable(re_batch_labels).cuda(GPU)\n",
    "    \n",
    "\n",
    "    criterion = HardTripletLoss2(margin = Margin).cuda(GPU)\n",
    "    triplet_loss= criterion(metric_network(attribute_network(batch_attributes_ext)), \n",
    "                            metric_network(batch_features_ext), re_batch_labels)\n",
    "    if triplet_loss == 0:\n",
    "        loss_zero_num = loss_zero_num + 1\n",
    "    metric_network.zero_grad()\n",
    "    attribute_network.zero_grad()\n",
    "    \n",
    "    triplet_loss.backward()\n",
    "    \n",
    "    attribute_network_optim.step()\n",
    "    metric_network_optim.step()\n",
    "    \n",
    "    if (episode+1)%200 == 0 or episode==0:\n",
    "        print(\"episode:\", episode+1, \"loss\", triplet_loss)\n",
    "        print('loss_zero_number= ',loss_zero_num)\n",
    "        #writer.add_scalar('data/loss_zero_number', loss_zero_num, episode)\n",
    "        loss_zero_num = 0\n",
    "        #writer.add_scalar('data/loss', triplet_loss, episode)\n",
    "    if (episode+1)%200 == 0 or episode==0:\n",
    "        print(\"Testing...\")\n",
    "        #attribute_network.eval()\n",
    "        zsl_accuracy = compute_accuracy_per_class(test_features, test_label, test_id, test_attributes)\n",
    "        gzsl_unseen_accuracy = compute_accuracy_per_class(test_features, test_label, np.arange(200), attributes)\n",
    "        gzsl_seen_accuracy  = compute_accuracy_per_class(test_seen_features, test_seen_label, np.arange(200), attributes)\n",
    "        H = 2 * gzsl_seen_accuracy * gzsl_unseen_accuracy / (gzsl_unseen_accuracy + gzsl_seen_accuracy)\n",
    "        print('zsl:', zsl_accuracy)\n",
    "        #print('zsl:', zsl_accuracy2)\n",
    "        print('gzsl: unseen=%.4f , seen=%.4f , h=%.4f' % (gzsl_unseen_accuracy , gzsl_seen_accuracy, H))\n",
    "        #print('gzsl: unseen=%.4f , seen=%.4f , h=%.4f' % (gzsl_unseen_accuracy2 , gzsl_seen_accuracy2, H2))\n",
    "        print('_'*100)\n",
    "        #writer.add_scalar('data/zsl_accuracy', zsl_accuracy, episode)\n",
    "        #writer.add_scalar('data/gzsl_unseen_accuracy', gzsl_unseen_accuracy, episode)\n",
    "        #writer.add_scalar('data/gzsl_seen_accuracy', gzsl_seen_accuracy, episode)\n",
    "        #writer.add_scalar('data/H', H, episode)\n",
    "#writer.export_scalars_to_json(\"./test.json\")\n",
    "#writer.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
